package co.yixiang.yshop.module.crm.controller.admin.crmworkwxcustomer;

import co.yixiang.yshop.framework.common.pojo.CommonResult;
import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.framework.common.util.object.BeanUtils;
import co.yixiang.yshop.module.crm.controller.admin.crmworkwxcustomer.vo.CrmWorkWxCustomerPageReqVO;
import co.yixiang.yshop.module.crm.controller.admin.crmworkwxcustomer.vo.CrmWorkWxCustomerRespVO;
import co.yixiang.yshop.module.crm.controller.admin.crmworkwxcustomer.vo.CrmWorkWxCustomerSaveReqVO;
import co.yixiang.yshop.module.crm.dal.dataobject.crmworkwxcustomer.CrmWorkWxCustomerDO;
import co.yixiang.yshop.module.crm.service.crmworkwxcustomer.CrmWorkWxCustomerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 企业微信客户")
@RestController
@RequestMapping("/crm/work-wx-customer")
@Validated
public class CrmWorkWxCustomerController {

    @Resource
    private CrmWorkWxCustomerService workWxCustomerService;

    @PostMapping("/create")
    @Operation(summary = "创建企业微信客户")
    @PreAuthorize("@ss.hasPermission('crm:work-wx-customer:create')")
    public CommonResult<Boolean> createWorkWxCustomer() {
        workWxCustomerService.createWorkWxCustomer();
        return success(true);
    }

    @PutMapping("/update")
    @Operation(summary = "更新企业微信客户")
    @PreAuthorize("@ss.hasPermission('crm:work-wx-customer:update')")
    public CommonResult<Boolean> updateWorkWxCustomer(@Valid @RequestBody CrmWorkWxCustomerSaveReqVO updateReqVO) {
        workWxCustomerService.updateWorkWxCustomer(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除企业微信客户")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('crm:work-wx-customer:delete')")
    public CommonResult<Boolean> deleteWorkWxCustomer(@RequestParam("id") Long id) {
        workWxCustomerService.deleteWorkWxCustomer(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得企业微信客户")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('crm:work-wx-customer:query')")
    public CommonResult<CrmWorkWxCustomerRespVO> getWorkWxCustomer(@RequestParam("id") Long id) {
        CrmWorkWxCustomerDO workWxCustomer = workWxCustomerService.getWorkWxCustomer(id);
        return success(BeanUtils.toBean(workWxCustomer, CrmWorkWxCustomerRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得企业微信客户分页")
    @PreAuthorize("@ss.hasPermission('crm:work-wx-customer:query')")
    public CommonResult<PageResult<CrmWorkWxCustomerRespVO>> getWorkWxCustomerPage(@Valid CrmWorkWxCustomerPageReqVO pageReqVO) {
        return success(workWxCustomerService.getWorkWxCustomerPage(pageReqVO));
    }



}